<?php

declare (strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 * @property int $id
 * @property string $message
 * @property string $line
 * @property string $file
 * @property string $url
 * @property string $params
 * @property string $headers
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 */

/**
 */
class ErrorLog extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'error_log';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['message', 'line', 'file', 'url', 'params', 'headers', 'created_at', 'updated_at'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    /**
     * 添加记录
     * @param $message
     * @param $line
     * @param $file
     * @param $url
     * @param $allParams
     * @param $header
     * @return void
     */
    public static function addLog($message, $line, $file, $url, $allParams, $header): void
    {
        self::create([
            'message'    => $message,
            'line'       => $line,
            'file'       => $file,
            'url'        => $url,
            'params'     => json_encode($allParams, JSON_UNESCAPED_UNICODE),
            'headers'    => json_encode($header, JSON_UNESCAPED_UNICODE),
            'created_at' => date('Y-m-d H:i:s'),
            'updated_at' => date('Y-m-d H:i:s'),
        ]);
    }
}
